package com.robusta.cityuate.activities;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.robusta.cityuate.R;
import com.robusta.cityuate.base.CityuateFragmentMenuActivity;
import com.robusta.cityuate.fragments.ReservationsListFragment;
import com.robusta.cityuate.fragments.ReservationsListFragment.ReservationType;

public class MyReservationsActivity extends CityuateFragmentMenuActivity
		implements ActionBar.TabListener {

	ActionBar.Tab tab, tab2;
	ReservationsListFragment[] frgs = new ReservationsListFragment[2];

	@Override
	public void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.my_reservations_list);
		getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		tab = getSupportActionBar().newTab();
		tab.setText(getString(R.string.coming_reservations));
		tab.setTabListener(this);
		
		tab2 = getSupportActionBar().newTab();
		tab2.setText(getString(R.string.past_reservations));
		tab2.setTabListener(this);
		
		getSupportActionBar().addTab(tab);
		getSupportActionBar().addTab(tab2);

	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		frgs[tab.getPosition()] = ReservationsListFragment
				.getInstant(tab.getPosition()==0? ReservationType.COMING:ReservationType.OLD);
		ft.replace(R.id.frag_holder, frgs[tab.getPosition()]);
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {

	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		ft.replace(R.id.frag_holder, frgs[tab.getPosition()]);

	}

}
